package com.zx.viewlearn.activity;

import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.MainThread;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.zx.viewlearn.R;

public class ViewLearnActivity16Vector extends AppCompatActivity {
    ImageView my_iv;
    ImageView my_iv_2;
    ImageView my_iv_3;


    boolean open = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_learn_activity16_vector);
        my_iv = findViewById(R.id.my_iv);
        my_iv = findViewById(R.id.my_iv);
        my_iv_2 = findViewById(R.id.my_iv_2);
        my_iv_3 = findViewById(R.id.my_iv_3);
        my_iv_2.setImageResource(R.drawable.myanimatedvector8_line);
        startAnimator(my_iv_2);
        startAnimator(my_iv_3);

    }
//
//    final Handler mHandler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//
//        }
//
//    };

    @Override
    protected void onResume() {
        super.onResume();
//        mHandler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//
//            }
//        }, 1000);
    }

    public void test(View view) {
        if (!open) {
            my_iv.setImageResource(R.drawable.myanimatedvector3);

        } else {
            my_iv.setImageResource(R.drawable.myanimatedvector3_close);

        }
        Drawable drawable = my_iv.getDrawable();
        if (drawable instanceof Animatable) {
            ((Animatable) drawable).start();
        }
        open = !open;
    }

    public void test2(View view) {
        my_iv_2.setImageResource(R.drawable.myanimatedvector8_9);
        startAnimator(my_iv_2);

    }

    private void startAnimator(ImageView view) {
        Drawable drawable = view.getDrawable();
        if (drawable instanceof Animatable) {
            if (((Animatable) drawable).isRunning()) {

            } else {
                ((Animatable) drawable).start();

            }
        }
    }
}
